using FireStarterModeller.BO;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestFirestarterUtils
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();

        }

        [Test]
        public void Test_GetNextUIOrder_NOItems_ShouldBeZero()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection<DMProperty> props = new BusinessObjectCollection<DMProperty>();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, props.Count);
            //---------------Execute Test ----------------------
            int nextUIOrder = FirestarterUtils.GetNextUIOrder(props);

            //---------------Test Result -----------------------
            Assert.AreEqual(0, nextUIOrder);
        }
        [Test]
        public void Test_GetNextUIOrder_OneItems_OrdinalPositionNull()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty};

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, propCol.Count);
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int nextUIOrder = FirestarterUtils.GetNextUIOrder(propCol);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, nextUIOrder);
        }
        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPositionNull()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty();
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, order, "Max order should be 2");
        } 
        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPosition_One_ShouldBeTwo()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty {OrdinalPosition = 1};
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, order, "Max order should be 2");
        }
        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPosition_Two_ShouldBeThree()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty {OrdinalPosition = 2};
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);
            //---------------Test Result -----------------------
            Assert.AreEqual(3, order, "Max order should be 3");
        }

        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPosition_Two_RemovedItemsWOrdinalPos_3_ShouldReturn4()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty {OrdinalPosition = 2};
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };
            propCol.RemovedBusinessObjects.Add(new DMProperty { OrdinalPosition = 3 });
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);
            //---------------Test Result -----------------------
            Assert.AreEqual(4, order, "Max order should be 4");
        }
        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPosition_Two_RemovedItemsWOrdinalPos_One_ShouldReturn_Three()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty {OrdinalPosition = 2};
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };
            propCol.RemovedBusinessObjects.Add(new DMProperty { OrdinalPosition = 1 });
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);
            //---------------Test Result -----------------------
            Assert.AreEqual(3, order, "Max order should be 4");
        }

        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPosition_Two_DeletedItemsWOrdinalPos_3_ShouldReturn4()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty {OrdinalPosition = 2};
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };
            propCol.MarkedForDeleteBusinessObjects.Add(new DMProperty { OrdinalPosition = 3 });
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);
            //---------------Test Result -----------------------
            Assert.AreEqual(4, order, "Max order should be 4");
        }

        [Test]
        public void Test_GetNextUIOrder_TwoItems_OrdinalPosition_Two_DeletedItemsWOrdinalPos_One_ShouldReturn_Three()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = new DMProperty();
            DMProperty dmProperty2 = new DMProperty {OrdinalPosition = 2};
            BusinessObjectCollection<DMProperty> propCol = new BusinessObjectCollection<DMProperty> { dmProperty, dmProperty2 };
            propCol.MarkedForDeleteBusinessObjects.Add(new DMProperty { OrdinalPosition = 1 });
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, propCol.Count, "PropCol should have 2 items");
            Assert.IsNull(dmProperty.OrdinalPosition);
            //---------------Execute Test ----------------------
            int order = FirestarterUtils.GetNextUIOrder(propCol);
            //---------------Test Result -----------------------
            Assert.AreEqual(3, order, "Max order should be 4");
        }

    }
}